//转换日期格式(时间戳转换为datetime格式)（返回 yyyy-MM-dd HH:mm:ss）
function changeDateFormat(cellval) {
    var dateVal = cellval + "";
    if (cellval != null) {
        var date = new Date(parseInt(dateVal.replace("/Date(", "").replace(")/", ""), 10));
        var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
        var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
        var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
        var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
        var seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
        return date.getFullYear() + "-" + month + "-" + currentDate + " " + hours + ":" + minutes + ":" + seconds;
    }
}

//转换日期格式(时间戳转换为datetime格式)（返回 HH:mm:ss）
function changeDateFormatHour(cellval) {
    var dateVal = cellval + "";
    if (cellval != null) {
        var date = new Date(parseInt(dateVal.replace("/Date(", "").replace(")/", ""), 10));
        var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
        var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
        var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
        var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
        var seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
        return   hours + ":" + minutes + ":" + seconds;
    }
}

function convertTimestamp(sj)
{
    var now = new Date(sj*1000);
    var   year=now.getFullYear();
    var   month=now.getMonth()+1;
    var   date=now.getDate();
    var   hour=now.getHours();
    var   minute=now.getMinutes();
    var   second=now.getSeconds();
    return   year+"-"+month+"-"+date+"   "+hour+":"+minute+":"+second;

}

//序列化表单
$.fn.serializeObject = function () {
    var o = {};
    var a = this.serializeArray();
    $.each(a, function () {
        if (o[this.name] !== undefined) {
            if (!o[this.name].push) {
                o[this.name] = [o[this.name]];
            }
            o[this.name].push(this.value || '');
        } else {
            o[this.name] = this.value || '';
        }
    });
    return o;
};




//获取ztree子节点id
function getChidID(obj) {
    var treeObj=$.fn.zTree.getZTreeObj(obj);
    var nodes=treeObj.getCheckedNodes(true);
    var dataR="";
    for(var i=0;i<nodes.length;i++){
        if(!nodes[i].isParent){
            dataR+=","+nodes[i].id; //获取选中节点的值
        }
    }
    return dataR.substr(1,dataR.length-1);
}
//获取ztree子节点name
function getChidName(obj) {
    var treeObj=$.fn.zTree.getZTreeObj(obj);
    var nodes=treeObj.getCheckedNodes(true);
    var dataR="";
    for(var i=0;i<nodes.length;i++){
        if(!nodes[i].isParent){
            dataR+=","+nodes[i].name; //获取选中节点的值
        }
    }
    return dataR.substr(1,dataR.length-1);
}
//获取ztree的id
function getAllID(obj) {
    var treeObj=$.fn.zTree.getZTreeObj(obj);
    var nodes=treeObj.getCheckedNodes(true);
    var dataR="";
    for(var i=0;i<nodes.length;i++){

        dataR+=","+nodes[i].id; //获取选中节点的值

    }
    return dataR.substr(1,dataR.length-1);
}
//获取ztree的name
function getAllName(obj) {
    var treeObj=$.fn.zTree.getZTreeObj(obj);
    var nodes=treeObj.getCheckedNodes(true);
    var dataR="";
    for(var i=0;i<nodes.length;i++){

        dataR+=","+nodes[i].name; //获取选中节点的值

    }
    return dataR.substr(1,dataR.length-1);
}
//指定选中
function setZtreeNode(NodeId,data){
    if(JSON.stringify(data)=="[]"){
        return ;
    }
    var treeObj = $.fn.zTree.getZTreeObj(NodeId);
    data.forEach(function (value, index, arr) {
        var node = treeObj.getNodeByParam("id", value.parkId, null);
        treeObj.checkNode(node, true, true);//指定选中ID的节点
    });

}

//禁用树的选择
function redonlyZtree(NodeId,data){

    /*    if(JSON.stringify(data)=="[]"){
     return ;
     }*/
    var treeObj = $.fn.zTree.getZTreeObj(NodeId);
    var node = treeObj.getNodes();
    for (var i=0, l=node.length; i < l; i++) {
        //父级和子级都禁用
        treeObj.setChkDisabled(node[i], true,true,true);
    }
}
//单下拉框 需传入指定字段
function getCodeSelect(url,obj,value) {
    $.get(url,function (dataJSON) {
        if(value==null){
            obj.select2({data: dataJSON, allowClear: true});
        }else{
            obj.val(value).select2({data: dataJSON, allowClear: true});
        }
    });
}

//已修改 为 查询所有房间
function getDataByDicCode(base,code){
    var resultData;
    $.ajax({
        type : "POST", //提交方式
        url : base+"/room/findAllRoom",//路径
        async:false,
        success : function(data) {//返回数据根据结果进行相应的处理
            resultData=data;
        }
    });

    return resultData;
}
//查询所有 还未下订单的房间
function getRoomByNoOrder(base,code){
    var resultData;
    $.ajax({
        type : "POST", //提交方式
        url : base+"/room/findRoomByNoOrder",//路径
        async:false,
        success : function(data) {//返回数据根据结果进行相应的处理
            resultData=data;
        }
    });

    return resultData;
}

function getDataByCode(base,code){
    var resultData;
    $.ajax({
        type : "POST", //提交方式
        url : base+"/sysDic/findDataByDicCode",//路径
        data :{"code":code},
        async:false,
        success : function(data) {//返回数据根据结果进行相应的处理
            resultData=data;
        }
    });

    return resultData;
}



function getMealName(base,meal_name){
    var resultData;
    $.ajax({
        type : "POST", //提交方式
        url : base+"/trMeal/list",//路径
        data :{"meal_name":meal_name},
        async:false,
        success : function(data) {//返回数据根据结果进行相应的处理
            resultData=data;
        }
    });

    return resultData;
}












function isNull(){
var flag=true;
    var mac=/^\s*$/;
    var required = $(".isNull");
     required.each(function () {
         $(this).css('border','');
         if($(this).val().match(mac)){

             $(this).focus();
             $(this).css('border','2px solid red');
             flag=false;
             return flag;
         }

    })
    return flag;
}

function isPhone(){
var flag=true;
    var required = $(".isPhone");
     required.each(function () {
         $(this).css('border','');
         if(!/^1[34578]\d{9}$/.test($(this).val())){

             $(this).focus();
             $(this).css('border','2px solid red');
             flag=false;
             return flag;
         }

    })
    return flag;
}



function isNum(){
var flag=true;
    var required = $(".isNum");
     required.each(function () {
         $(this).css('border','');
         if(isNaN($(this).val())){
             $(this).focus();
             $(this).css('border','2px solid red');
             flag=false;
             return flag;
         }

    })
    return flag;
}

//将时间戳转换成日期
function GetDateByShiJianChuo(cellval) {
var dateVal = cellval + "";
if(cellval != null){
         var date = new Date(parseInt(cellval.replace("/Date(", "").replace(")/", "")));
         var dateStr = date.toLocaleDateString();
         dateStr = dateStr.replace("/", "-").replace("/", "-");
         return dateStr;
         }
 }





function isNo(){
    var flag=true;
    var required = $(".isNo");
    required.each(function () {
        $(this).css('border','');
        if(!/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test($(this).val())){

            $(this).focus();
            $(this).css('border','2px solid red');
            flag=false;
            return flag;
        }

    })
    return flag;
}

function DateFormat(cellval) {
    var dateVal = cellval + "";
    if (cellval != null) {
        var date = new Date(parseInt(dateVal.replace("/Date(", "").replace(")/", ""), 10));
        var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
        var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
        //var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
       // var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
        //var seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
       // return date.getFullYear() + "-" + month + "-" + currentDate + " " + hours + ":" + minutes + ":" + seconds;
       return date.getFullYear() + "-" + month + "-" + currentDate;
    }
}









//去空格
function Trim(str)
{
    return str.replace(/(^\s*)|(\s*$)/g, "");
}